package mode

import (
	"time"

	"gorm.io/gorm"
)

/**
pm表
可以被多个角色关联
仅可以关联一个menu
*/

type Db_pm struct {
	gorm.Model
	Fullpath string     `json:"fullpath" form:"fullpath" binding:"required" required_msg:" fullpath 为必填项目" validate:"required" gorm:"comment:'对比menus表必要属性';type:varchar(60);not null;unique;"`
	Url      string     `json:"url" form:"url" binding:"required" required_msg:" url 为必填项目" validate:"required" gorm:"type:varchar(60);not null;"`
	Method   string     `json:"method" form:"method" binding:"required" required_msg:" method 为必填项目" validate:"required" gorm:"type:varchar(6);not null;"`
	Desc     string     `json:"desc" form:"desc" binding:"max=65"  gorm:"size:65"`
	Role     []Db_roles `json:"-" gorm:"many2many:Roles_Pm;joinForeignKey:Pm_Id;joinReferences:Role_Id"`
}

func (m *Db_pm) UpdatePm(acPm *Db_pm) {
	m.UpdatedAt = time.Now()
	m.Url = acPm.Url
	m.Method = acPm.Method
	m.Desc = acPm.Desc
	m.Fullpath = acPm.Fullpath
}

// type Db_pm struct {
// 	gorm.Model
// 	Url    string `gorm:"type:varchar(60);not null;unique"`
// 	Method string `gorm:"type:varchar(6);not null;"`
// 	Desc   string `gorm:"size:65"`
// }

/** 引用*/
// type Db_pm struct {
// 	gorm.Model
// 	Url    string  `json:"url" form:"url" gorm:"type:varchar(60);not null;unique"`
// 	Method string  `json:"method" form:"method" gorm:"type:varchar(6);not null;"`
// 	Desc   string  `json:"desc" binding:"max=65" gorm:"size:65"`
// 	MenuId Db_menu `json:"menu_id" gorm:"foreignKey:Api_id"`
// }
